package com.fth.learn.chapter05;

import java.util.Arrays;

/**
 * 试卷上的编程题
 * YiMi
 *
 * @author YiMi
 * @version 1.0
 * @date 2023/7/12 9:00
 */

public class LearnArray03 {

    public static void question1() {
            int arr[][]= {{22,66,44},{77,33,88},{25,45,65},{11,66,99}};
            int sum = 0;
            for(int i = 0; i < arr.length; i++) {
                //遍历每个一维数组
                for(int j = 0; j < arr[i].length; j++) {
                    sum += arr[i][j];
                }
            }
            System.out.println("公司营销总和是" + sum);
    }


    public static void question2(){
        int arr[]={10,52,65,4,5,8,5,452,45};
        for (int j = 0; j < arr.length - 1; j++) {
            for (int i = 0; i < arr.length - 1 - j; i++) {
                if (arr[i] > arr[i + 1]) {
                    //swap
                    arr[i] = arr[i] + arr[i + 1];
                    arr[i + 1] = arr[i] - arr[i + 1];
                    arr[i] = arr[i] - arr[i + 1];
                }
            }
        }
        System.out.print(Arrays.toString(arr));
    }

    public static void question3(){

        int arr[]={10,52,65,4,5,8,5,452,45};
        int max= arr[0];
        int maxindex = 0;
        int secend = 0;
        int secendindex = 0;
        for(int i=0;i<arr.length;i++){
            if(max<arr[i]){
                secend=max;
                secendindex=maxindex;
                max=arr[i];
                maxindex=i;
            }else {//max>=arr[i]
                if(secend<arr[i]){
                    secend=arr[i];
                    secendindex=i;
                }
            }
        }
        System.out.println("第二大数是"+secend+"角标是"+secendindex);
    }






    public static void main(String[] args) {
        question1();
        question2();
        question3();

    }


}
